<template>
    <div>
        <p>短信验证码登录</p>
        <van-form @submit="onSubmit">
            <van-cell-group inset>
                <van-field v-model="username" name="username" placeholder="国家和地区"
                    :rules="[{ required: true, message: '国家和地区' }]" />
                <!-- 通过 pattern 进行正则校验 -->
                <van-field v-model="phone" name="phone" placeholder="手机号" :rules="[{ pattern, message: '请输入手机号' }]" />
            </van-cell-group>
            <van-cell-group inset>
                <van-field v-model="sms" center clearable placeholder="请输入短信验证码">
                    <template #button>
                        <van-button size="small" type="primary">发送验证码</van-button>
                    </template>
                </van-field>
            </van-cell-group>
            <div style="margin: 16px;">
                <van-button round block type="primary" native-type="submit">
                    登录
                </van-button>
            </div>
        </van-form>

    </div>
</template>

<script setup>
import { ref } from 'vue';
import { loginApi } from '@/api/api';
import { showSuccessToast, showFailToast } from 'vant';
let username = ref('')
let login = ref([])
const onSubmit = () => {
    loginApi(username.value).then(res => {
        console.log('登录数据', res)
        if (res.data.code == 0) {
            showSuccessToast('登录成功')
        }
        else {
            showFailToast('登录成功')
        }

    })
}
let phone = ref('')
let pattern = /^[3-9]\d[9]$/
let sms = ref('')
let time = ref(5)




</script>

<style lang="scss" scoped>
p {
    text-align: center;
    font-size: 20px;
    color: #fff;
    background: black;
    height: 60px;


}
</style>